<template>
  <footer class="footer" v-if="list.length>0">
    <span class="todo-count" >剩余<strong>{{leftTask}}</strong></span>
    <ul class="filters">
      <!-- 7.4 -->
      <li>
        <a @click="$emit('changeTypeFn','all')" 
        :class="{selected:type=='all'}" href="javascript:;" >全部</a>
      </li>
      <li>
        <a @click="$emit('changeTypeFn','no')" 
        :class="{selected:type=='no'}" href="javascript:;">未完成</a>
      </li>
      <li>
        <a @click="$emit('changeTypeFn','yes')" 
        :class="{selected:type=='yes'}" href="javascript:;" >已完成</a>
      </li>
    </ul>
    <button class="clear-completed" @click="clear" v-show="isclear">清除已完成</button>
  </footer>
</template>

<script>
export default {
  props:{
    list:{
      type:Array,
      required:true,
    },
    // 7.3接收
    type:String
  },
  // 5 统计剩余未完成数量
  computed:{
    leftTask() {
      return this.list.filter(item => item.isDone === false).length
    },
    // 清除已完成按钮的显示域隐藏(有一项完成就显示)
    isclear() {
      return this.list.some(item => item.isDone)
    }
  },
  methods:{
    //6 清空已完成
    clear() {
      this.$emit('clear')
    }
  }
}
</script>